$(function(){
	var user = getCurrLoginUser();
	if(user.type == "0"){
		$("#pd").remove();
	} else{
		$("#meal_sub").attr("disabled","disabled");
		$("#over_time_sub").attr("disabled","disabled");
		$(':radio[name="type"]').attr("disabled","disabled");
//		$("#wg").attr("readonly",true);
		$("#wg").remove();
	}
	if($.getUrlParam("isShow")){
		$("#id_card_no").attr("disabled","disabled");
		$("#real_name").attr("disabled","disabled");
		$("#mobile_no").attr("disabled","disabled");
		$("#pd").remove();
		$("#save").remove();
		$("#cancel").html("返回");
	}
	initUser();
})

function initUser(){
	var data = {
			"USER_ID":$.getUrlParam("user_id")
	}
	$.jsonAjax("userServlet","getUserInfo",data,null,false,function(rtnData){
		if(!isEmpty(rtnData)&&rtnData.data.status=="success"){
			var list = rtnData.data.content;
			var dataJson = list[0];
			$("#user_id").val(processUndefined(dataJson.USER_ID));
			$("#user_name").val(processUndefined(dataJson.USER_NAME));
			$("#real_name").val(processUndefined(dataJson.REAL_NAME));
			$("#id_card_no").val(processUndefined(dataJson.ID_CARD_NO));
			$("#id_card_no_hide").val(processUndefined(dataJson.ID_CARD_NO));
			if("0"==processUndefined(dataJson.SEX)){
				$(':radio[name="sex"]').eq(1).attr("checked",true); 
			} else{
				$(':radio[name="sex"]').eq(0).attr("checked",true); 
			}
			if("0"==processUndefined(dataJson.TYPE)){
				$(':radio[name="type"]').eq(1).attr("checked",true); 
			} else{
				$(':radio[name="type"]').eq(0).attr("checked",true); 
			}
			
			$("#wage").val(parseFloat(processUndefined(dataJson.WAGE))/100);
			$("#meal_sub").val(parseFloat(processUndefined(dataJson.MEAL_SUB))/100);
			$("#over_time_sub").val(parseFloat(processUndefined(dataJson.OVER_TIME_SUB))/100);
			$("#mobile_no").val(processUndefined(dataJson.MOBILE_NO));
		} 
	},null);
}

function save(){
	var mainForm = $("#mainForm");
	if(mainForm.isValid()){
		var sex = $(':radio[name="sex"]:checked').val();
		var type = $(':radio[name="type"]:checked').val();
		var id_card_no = null;
		if($("#id_card_no_hide").val()!=$("#id_card_no").val()){
			id_card_no=$("#id_card_no").val();
		}
		var data = {
				"USER_ID"      :$("#user_id").val(),
				"USER_NAME"    :$("#user_name").val(),
				"REAL_NAME"    :$("#real_name").val(),
				"ID_CARD_NO"   :id_card_no,
				"PASSWD"  	   :$("#passWd").val(),
				"WAGE"     	   :$("#WAGE").val(),
				"MEAL_SUB"     :$("#meal_sub").val(),
				"OVER_TIME_SUB":$("#over_time_sub").val(),
				"MOBILE_NO"    :$("#mobile_no").val(),
				"SEX"          :sex,
				"TYPE"         :type,
				"OPERTYPE"	   :"modify"
		}
		$.jsonAjax("userServlet","updateUserInfo",data,null,false,function(rtnData){
			if(!isEmpty(rtnData)&&rtnData.data.status=="success"){
				art.dialog.message("succeed","修改用户信息成功！",function(){
					art.dialog.open.api.close();
					art.dialog.open.origin.queryListData();
				});
			} else{
				art.dialog.message("error","修改用户失败！",null);
			}
		});
	} 
}

function closeWin(){
	art.dialog.open.api.close();
}